<?php
class Amain {
	public static function main($sfuncode) {
		list($classid, $funcode) = explode('-', $sfuncode, 2);
		switch ($classid) {
			case 1:
				require 'login.lib.php';
				Alogin::main($funcode);
				break;
			case 2:
				require 'register.lib.php';
				Aregister::main($funcode);
				break;
			default:
				sview::$view->assign_error(404, lang::text(404));
		}
	}

	//处理公共逻辑 Push推送的编号id
	public static function onesignal($userid) {
		$device = $_SERVER['HTTP_USER_AGENT'];
		$player = isset(sview::$ctrl['device'])? trim(sview::$ctrl['device']):'';
		$orm    = model::load('live/onesignal');
		if ($device && $player) {
			$orm->get_orm()->where('player', $player)->where('userid', $userid, orm::OP_NE)->delete();
			$row = $orm->get_one($userid);
			if ($row) {
				if (!empty($row['player']) && $player != $row['player']) {
					api_sitemsg::push($userid, lang::text(80118), lang::text(80118), 9);
				}
				$field = array('device'=>$device, 'player'=>$player, 'stime'=>config::$nowtime);
				$orm->save($userid, $field);
			} else {
				$field = array('userid'=>$userid, 'device'=>$device, 'player'=>$player, 'status'=>1, 'stime'=>config::$nowtime);
				$orm->new_one($field);
			}
		} else {
			$orm->delete($userid);
		}
	}
}